package com.webside.listener;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletContext;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.ServletContextAware;
import com.webside.listener.vo.Channel;
import com.webside.series.mapper.BdictionaryMapper;
import com.webside.series.model.Bdictionary;

public class InitialDataListener implements InitializingBean, ServletContextAware {
	@Autowired
	private BdictionaryMapper bdictionaryMapper;
	private String videoFolder;

	@Override
	public void setServletContext(ServletContext servletContext) {
		BaseData.video_folder=videoFolder;
		
		BaseData.channels = new ArrayList<Channel>();

		List<Bdictionary> dicChannels = bdictionaryMapper.selectAllChannels();
		Channel channel;
		for (int i = 0; i < dicChannels.size(); i++) {
			channel=new Channel();
			Bdictionary dicChannel=dicChannels.get(i);
			channel.setChannel(dicChannel);
			channel.setName(dicChannel.getName());
			channel.setCode(dicChannel.getCode());
			List<Bdictionary> allcode= bdictionaryMapper.selectChannels(dicChannel);
			List<Bdictionary> types=bdictionaryMapper.selectTypeByChannel(dicChannel);
			List<Bdictionary> kinds= bdictionaryMapper.selectKindByChannel(dicChannel);
			channel.setAllChannels(allcode);
			channel.setDramaTypes(types);
			channel.setSeriesKinds(kinds);
			
			BaseData.channels.add(channel);
			System.out.println("init data finished!");
		}
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		// TODO Auto-generated method stub

	}

	public String getVideoFolder() {
		return videoFolder;
	}

	public void setVideoFolder(String videoFolder) {
		this.videoFolder = videoFolder;
	}

}
